﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Royaumes_Libres.Database;

namespace Royaumes_Libres
{
    /// <summary>
    /// Pour setter les valeurs par défaut des buildings.
    /// </summary>
    /// <remarks>Patrick Chabot</remarks>
    public partial class ucBuildingAdmin : System.Web.UI.UserControl
    {
        protected cBuildingsAdmin pBuilding;
        public cBuildingsAdmin Building { set { this.pBuilding = value; } }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.InitControl();
        }

        protected void InitControl()
        {
            this.Image1.ImageUrl = this.pBuilding.ImgUrl;
            this.lblName.Text = cText.GetText(this.pBuilding.Name);
            
            this.lblPrice.Text = cText.GetText("Price");
            this.lblTimber.Text = cText.GetText("Timber");
            this.lblOre.Text = cText.GetText("Ore");
            this.lblMana.Text = cText.GetText("Mana");
            this.txtTimber.Text = this.pBuilding.Timber.ToString();
            this.txtMana.Text = this.pBuilding.Mana.ToString();
            this.txtOre.Text = this.pBuilding.Ore.ToString();

            this.lblBonus.Text = cText.GetText("Bonus");
            this.lblBTimber.Text = cText.GetText("Timber");
            this.lblBOre.Text = cText.GetText("Ore");
            this.lblBMana.Text = cText.GetText("Mana");
            this.lblBFood.Text = cText.GetText("Food");
            this.lblBPop.Text = cText.GetText("Pop");
            this.txtBTimber.Text = this.pBuilding.BonusTimber.ToString();
            this.txtBOre.Text = this.pBuilding.BonusOre.ToString();
            this.txtBMana.Text = this.pBuilding.BonusMana.ToString();
            this.txtBFood.Text = this.pBuilding.BonusFood.ToString();
            this.txtBPop.Text = this.pBuilding.BonusPopulation.ToString();
        }

        public void Save()
        {
            this.pBuilding.Timber = int.Parse(this.txtTimber.Text);
            this.pBuilding.Mana = int.Parse(this.txtMana.Text);
            this.pBuilding.Ore = int.Parse(this.txtOre.Text);

            this.pBuilding.BonusTimber = decimal.Parse(this.txtBTimber.Text);
            this.pBuilding.BonusOre = decimal.Parse(this.txtBOre.Text);
            this.pBuilding.BonusMana = decimal.Parse(this.txtBMana.Text);
            this.pBuilding.BonusFood = decimal.Parse(this.txtBFood.Text);
            this.pBuilding.BonusPopulation = decimal.Parse(this.txtBPop.Text);

            this.pBuilding.SaveBuilding();
        }
    }
}